home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-10-10 | 7.0 KB | 232 lines | [TEXT/MMCC] |
- /*
- File: AppleEventHandling.cp
-
- Contains: Minimalist support for the required and Display Manager AppleEvents
- We also support openning and printing “LetterSpec” documents for AOCE.
-
- To really support AppleScript™, we’ll need to do ALOT more work in here.
-
- Written by: Dave Falkenburg
-
- Copyright: © 1993-94 by Dave Falkenburg, all rights reserved.
-
- Change History (most recent first):
-
- */
-
- #include <Types.h>
- #include <AppleEvents.h>
- #include <Errors.h>
- #include <Displays.h> // for Display Manager AppleEvent constants
- #include <OCEStandardMail.h> // for LetterSpec
-
- #include "AppLib.h"
- #include "AppleEventHandling.h"
-
- void InstallAppleEventHandlers(void)
- {
- // It’s probably more efficient to use a table to install these handlers…
-
- (void) AEInstallEventHandler (kCoreEventClass, kAEOpenApplication, NewAEEventHandlerProc(HandleOpenApplication), 0, false);
- (void) AEInstallEventHandler (kCoreEventClass, kAEOpenDocuments, NewAEEventHandlerProc(HandleOpenDocuments), 0, false);
- (void) AEInstallEventHandler (kCoreEventClass, kAEPrintDocuments, NewAEEventHandlerProc(HandlePrintDocuments), 0, false);
- (void) AEInstallEventHandler (kCoreEventClass, kAEQuitApplication, NewAEEventHandlerProc(HandleQuitApplication), 0, false);
-
- // regardless of whether or not we have the display manager, go ahead and register an AppleEvent handler
- (void) AEInstallEventHandler (kCoreEventClass, kAESystemConfigNotice, NewAEEventHandlerProc(HandleSystemConfigNotice), 0, false);
- }
-
- OSErr CheckAppleEventForMissingParams(AppleEvent *pAppleEvent)
- {
- DescType aReturnedType;
- Size aActualSize;
- OSErr anErr;
-
- anErr = AEGetAttributePtr(pAppleEvent,keyMissedKeywordAttr,typeWildCard,
- &aReturnedType,nil,0,&aActualSize);
-
- switch (anErr)
- {
- case errAEDescNotFound : // If we couldn’t find the error attribute
- anErr = noErr; // everything is ok, return noErr
- break;
- case noErr : // We found an error attribute, so
- anErr = errAEEventNotHandled; // tell the client we ignored the event
- break;
- // Something else happened, return it
- }
- return anErr;
- }
-
- OSErr ForEachDocumentInList(AEDescList theDocumentList,EachDocumentProcPtr pDocumentProc,void * pDocumentParam)
- {
- long aDocumentCount;
- long aDocumentIndex;
- DescType aReturnedType;
- Size aActualSize;
- LetterDescriptor aLetterDesc;
- AEKeyword aKeyword;
- OSErr anErr;
-
- anErr = AECountItems(&theDocumentList,&aDocumentCount);
- if (anErr == noErr)
- for (aDocumentIndex = 1; (anErr == noErr) && (aDocumentIndex <= aDocumentCount); ++aDocumentIndex)
- {
- // What kind of document is it?
- anErr = AESizeOfNthItem(&theDocumentList, aDocumentIndex, &aReturnedType,&aActualSize);
- if (anErr == noErr)
- // Is it an AOCE letter?
- if (aReturnedType == typeLetterSpec)
- {
- // It’s a letter
- aLetterDesc.onDisk = false;
- anErr = AEGetNthPtr(&theDocumentList,aDocumentIndex,typeLetterSpec,&aKeyword,&aReturnedType,
- (Ptr) &aLetterDesc.u.mailboxSpec, sizeof(aLetterDesc.u.mailboxSpec),&aActualSize);
- }
- else
- {
- // It’s just a normal document file
- aLetterDesc.onDisk = true;
- anErr = AEGetNthPtr(&theDocumentList,aDocumentIndex,typeFSS,&aKeyword,&aReturnedType,
- (Ptr) &aLetterDesc.u.fileSpec,sizeof(aLetterDesc.u.fileSpec),&aActualSize);
- }
- if (anErr == noErr)
- (*pDocumentProc)(&aLetterDesc, pDocumentParam);
- }
-
- return anErr;
- }
-
- pascal OSErr HandleOpenApplication(AppleEvent *pAppleEvent,AppleEvent * /*pReply*/,long /*theRefCon*/)
- {
- OSErr anErr;
-
- anErr = CheckAppleEventForMissingParams(pAppleEvent);
- #define RESPONDTOOPENAPPEVENT 1
- #if RESPONDTOOPENAPPEVENT
- if (anErr == noErr)
- anErr = OpenNewDocument();
- #endif // RESPONDTOOPENAPPEVENT
- return anErr;
- }
-
- pascal OSErr HandleOpenDocuments(AppleEvent *pAppleEvent,AppleEvent * /*pReply*/,long /*theRefCon*/)
- {
- OSErr anErr;
- AEDescList aDocumentList;
-
- anErr = AEGetParamDesc(pAppleEvent, keyDirectObject, typeAEList, &aDocumentList);
- if (anErr == noErr)
- anErr = AEGetParamDesc(pAppleEvent, keyDirectObject, typeAEList, &aDocumentList);
- if (anErr == noErr)
- anErr = CheckAppleEventForMissingParams(pAppleEvent);
- if (anErr == noErr)
- {
- anErr = ForEachDocumentInList(aDocumentList, &OpenDocument, nil);
- (void) AEDisposeDesc(&aDocumentList);
- }
- return anErr;
- }
-
- pascal OSErr HandlePrintDocuments(AppleEvent *pAppleEvent,AppleEvent * /*pReply*/,long /*theRefCon*/)
- {
- OSErr anErr;
- AEDescList aDocumentList;
- #if qUseQuickDrawGX
- Boolean aIsDraggedToDesktopPrinter = false;
- AEDescList aDesktopPrinterList;
- #endif
-
- anErr = AEGetParamDesc(pAppleEvent, keyDirectObject, typeAEList, &aDocumentList);
-
- #if qUseQuickDrawGX
- if (anErr == noErr)
- if ( ! AEGetAttributeDesc(pAppleEvent, keyOptionalKeywordAttr, typeAEList, &aDesktopPrinterList))
- aIsDraggedToDesktopPrinter = true;
- #endif
- if (anErr == noErr)
- anErr = CheckAppleEventForMissingParams(pAppleEvent);
-
- if (anErr == noErr)
- #if qUseQuickDrawGX
- {
- FSSpec aPrinterFSSpec;
-
- if (aIsDraggedToDesktopPrinter)
- {
- DescType aReturnedType;
- Size aActualSize;
- AEKeyword aKeyword;
-
- anErr = AEGetNthPtr(&aDesktopPrinterList,1, typeFSS,&aKeyword, &aReturnedType,
- (Ptr) &aPrinterFSSpec, sizeof(FSSpec), &aActualSize);
-
- (void) AEDisposeDesc(&aDesktopPrinterList);
- }
- if (anErr == noErr)
- {
- anErr = ForEachDocumentInList(aDocumentList, &PrintDocument, (aIsDraggedToDesktopPrinter ? &aPrinterFSSpec : NULL));
- (void)AEDisposeDesc(&aDocumentList);
- }
- }
- #else
- anErr = ForEachDocumentInList(aDocumentList,&PrintDocument, nil);
- #endif
-
- return anErr;
- }
-
- pascal OSErr HandleQuitApplication(AppleEvent *pAppleEvent,AppleEvent * /* pReply */,long /* theRefCon */)
- {
- OSErr anErr;
-
- anErr = CheckAppleEventForMissingParams(pAppleEvent);
- if (anErr == noErr)
- {
- gDone = QuitApplication();
-
- if ( ! gDone)
- anErr = userCanceledErr;
- }
- return anErr;
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //
- // Display Manager Suite is “Under Construction”
- //
- // To Do: Check ERS for Display Manager events
- pascal OSErr HandleSystemConfigNotice(AppleEvent *pAppleEvent,AppleEvent * /* pReply */,long /* theRefCon */)
- {
- AEDescList aDisplayList;
- long aDisplayCount;
- long aDisplayIndex;
- OSErr anErr;
-
- DebugStr((StringPtr) "\pGot a Display Manager Event!");
-
- if ((anErr = AEGetParamDesc(pAppleEvent,kAEDisplayNotice,typeAEList,&aDisplayList)) != noErr)
- return anErr;
-
- if ((anErr = CheckAppleEventForMissingParams(pAppleEvent)) != noErr)
- return anErr;
-
- if ((anErr = AECountItems(&aDisplayList,&aDisplayCount)) != noErr)
- return anErr;
-
- for (aDisplayIndex = 1; aDisplayIndex<=aDisplayCount; aDisplayIndex++)
- {
- DebugStr((StringPtr) "\pProcessing a display");
- // Gather up all the old and new display rectangles into an oldDeskRegion and a newDeskRegion
- }
-
-
- // run through all windows calling keeping all windows which were onscreen in the oldDeskRegion
- // onscreen in the new world. We should really be calling a method to do this so that windows
- // can individually deal with things in a manner which they can override.
-
-
- return errAEEventNotHandled; // we really don’t handle this yet...
- }
-